package com.ruoyi.repair.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.aspectj.weaver.loadtime.Aj;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.repair.domain.PropertyRepair;
import com.ruoyi.repair.service.IPropertyRepairService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 报修单Controller
 * 
 * @author ruoyi
 * @date 2025-10-27
 */
@RestController
@RequestMapping("/repair/repair")
public class PropertyRepairController extends BaseController
{
    @Autowired
    private IPropertyRepairService propertyRepairService;

    /**
     * 查询报修单列表
     */
    @PreAuthorize("@ss.hasPermi('repair:repair:list')")
    @GetMapping("/list")
    public TableDataInfo list(PropertyRepair propertyRepair)
    {
        startPage();
        List<PropertyRepair> list = propertyRepairService.selectPropertyRepairList(propertyRepair);
        return getDataTable(list);
    }

    /**
     * 导出报修单列表
     */
    @PreAuthorize("@ss.hasPermi('repair:repair:export')")
    @Log(title = "报修单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PropertyRepair propertyRepair)
    {
        List<PropertyRepair> list = propertyRepairService.selectPropertyRepairList(propertyRepair);
        ExcelUtil<PropertyRepair> util = new ExcelUtil<PropertyRepair>(PropertyRepair.class);
        util.exportExcel(response, list, "报修单数据");
    }

    /**
     * 获取报修单详细信息
     */
    @PreAuthorize("@ss.hasPermi('repair:repair:query')")
    @GetMapping(value = "/{repairId}")
    public AjaxResult getInfo(@PathVariable("repairId") Long repairId)
    {
        return success(propertyRepairService.selectPropertyRepairByRepairId(repairId));
    }

    /**
     * 新增报修单
     */
    @PreAuthorize("@ss.hasPermi('repair:repair:add')")
    @Log(title = "报修单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PropertyRepair propertyRepair)
    {
        return toAjax(propertyRepairService.insertPropertyRepair(propertyRepair));
    }

    /**
     * 修改报修单
     */
    @PreAuthorize("@ss.hasPermi('repair:repair:edit')")
    @Log(title = "报修单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PropertyRepair propertyRepair)
    {
        return toAjax(propertyRepairService.updatePropertyRepair(propertyRepair));
    }

    /**
     * 删除报修单
     */
    @PreAuthorize("@ss.hasPermi('repair:repair:remove')")
    @Log(title = "报修单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{repairIds}")
    public AjaxResult remove(@PathVariable Long[] repairIds)
    {
        return toAjax(propertyRepairService.deletePropertyRepairByRepairIds(repairIds));
    }


    @PreAuthorize("@ss.hasPermi('repair:repair:add')")
    @Log(title = "报修单", businessType = BusinessType.INSERT)
    @PostMapping("/submitRepair")
    public AjaxResult submitRepair(@RequestBody PropertyRepair propertyRepair)
    {
        return AjaxResult.success(propertyRepairService.submitRepair(propertyRepair));
    }
}
